#!/usr/bin/env python

import cherrypy
import sqlite3 
import os
import webAuth
from jinja2 import Environment, FileSystemLoader



#$http://tools.cherrypy.org/wiki/Databases


# define page loader
env = Environment(loader=FileSystemLoader(os.getcwd() + '/templates'))


def render_template(template_name, **context):
    extensions = context.pop('extensions', [])
    globals = context.pop('globals', {})
    
    jinja_env = Environment(
        loader = FilesystemLoader(os.getcwd(), 'templates'),
        extensions=extesions,
    )
    jinja_env.globals.update(globals)
    
    return jinja_env.get_template(template_name).render(context)







class requireLogin:
    print "foo"

class HelloWorld:
   
    def index(self):
        
        info = {}
        data = {}
  
        timeout = cherrypy.session
        info['addr'] = cherrypy.request.remote.ip
        info['port'] = cherrypy.request.remote.port
        info['host'] = cherrypy.request.remote.name
        #info['hdrMap'] = cherrypy.request.headerMap
        
        cherrypy.session['HelloWorld'] = 'Set'

        


        data = {'name': 'State_Your_Name', 'to': timeout, 'data': [{'this': 'a', 'that': '1'}, {'this': 'b', 'that': '2'},{'this': 'c', 'that': '3'} ] }

        template = env.get_template('test.html')
         
        
        #return  render_template('test.tmpl', data,)
        return  template.render(data)
        
    index.exposed = True    

    
    
 
       

        
        
    





cherrypy.quickstart(HelloWorld(), '/', 'conf/server.cfg')
